
#include <cstdio>
#include <gtest/gtest.h>
#include <string>
#include "../tools/tools_util.h"
#include "./../../log_module/log_module_define.h"

void PrintUrlInfo(UrlInfo & info)
{
    printf("domain:%s\tprotocol:%s\tport:%d\tpath:%s.\n", info.domain.c_str(), info.protocol.c_str(), info.port, info.resource_path.c_str());
    for (auto & data : info.server_vec)
    {
        printf("ip:%s port:%d.\n", data.ip.c_str(), data.port);
    }
}

TEST(HttpParser, Https)
{
    std::string url = "https://baidu.com";
    auto url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
}

TEST(HttpParser, UsePort)
{
    std::string url = "https://baidu.com:443";
    auto url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
}

TEST(HttpParser, UseResource)
{
    std::string url = "https://baidu.com:443/index";
    auto url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
    url = "https://baidu.com/index";
    url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
}
TEST(HttpParser, RtmpUseResource)
{
    std::string url = "rtmp://baidu.com:443/app/index";
    auto url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
    url = "rtmp://baidu.com/app/index";
    url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
}

TEST(HttpParser, UseIpAndPort)
{
    std::string url = "http://127.0.0.1:443/app/index";
    auto url_info = ParseUrlData(url);
    PrintUrlInfo(url_info);
}

TEST(GetAddrInfo, HttpProtocol)
{
    std::string url = "https://baidu.com";
    UrlInfo info;
    auto result = GetServerAddrInfo(url, info);
    PrintUrlInfo(info);
	(void)result;
}

int main(int argc, char * argv[])
{
    testing::InitGoogleTest();
    LogModuleConfig config;
    config.m_log_level = "trace";
    config.m_file_name = argv[0];
    LogModule::Instance()->InitModule(config);
    return RUN_ALL_TESTS();
}
